package leetcode.code1652;

import java.util.Arrays;

public class Solution1 {
	public int[] decrypt(int[] code, int k) {
		if (k == 0) {
			Arrays.fill(code, 0);
			return code;
		}
		int n = code.length;
		int l = k > 0 ? 1 : n + k;
		int r = k > 0 ? k : n - 1;
		int w = 0;
		for (int i = l; i <= r; i++) {
			w += code[i];
		}
		int[] ans = new int[n];
		for (int i = 0; i < code.length; i++) {
			ans[i] = w;
			w -= code[l];
			l = (l + 1) % n;
			r = (r + 1) % n;
			w += code[r];
		}
		return ans;
	}
}
